#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>

typedef long long ll;

const int N = 9, base = 28;
int n, score[N], tmp[N], has[N], rw, rp;
std::map<ll, int> map;

int dfs(int i, int j) {
  if (i == n) { return 1; }
  if (j > n) {
    if (tmp[i] != score[i]) return 0;
    for (int k = i + 1; k <= n; ++k) has[k] = score[k] - tmp[k];
    ll hash = 0;
    std::sort(has + i + 1, has + n + 1);
    for (int k = i + 1; k <= n; ++k) hash = hash * base + has[k];
    if (map.find(hash) != map.end()) return map[hash];
    return map[hash] = dfs(i + 1, i + 2);
  }
  int res = 0;
  if (tmp[i] + 3 <= score[i] && rw) {
    tmp[i] += 3, rw--;
    res += dfs(i, j + 1);
    tmp[i] -= 3, rw++;
  }
  if (tmp[j] + 3 <= score[j] && rw) {
    tmp[j] += 3, rw--;
    res += dfs(i, j + 1);
    tmp[j] -= 3, rw++;
  }
  if (tmp[i] + 1 <= score[i] && tmp[j] + 1 <= score[j] && rp) {
    tmp[i]++, tmp[j]++, rp--;
    res += dfs(i, j + 1);
    tmp[i]--, tmp[j]--, rp++;
  }
  return res;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P3154 [CQOI2009]循环赛.in", "r", stdin);
  freopen("P3154 [CQOI2009]循环赛.out", "w", stdout);
#endif
#endif

  scanf("%d", &n);
  int sum = 0;
  for (int i = 1; i <= n; ++i) { scanf("%d", &score[i]), sum += score[i]; }
  rw = sum - n * n + n, rp = ((n * n - n) >> 1) - rw;
  std::sort(score + 1, score + n + 1,
            [](const int &lhs, const int &rhs) { return lhs > rhs; });
  printf("%d", dfs(1, 2));
  return 0;
}
